/*     */ package com.zimbra.cs.mailbox.acl;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.ShareInfoData;
/*     */ import com.zimbra.cs.mailbox.ACL;
/*     */ import com.zimbra.cs.mailbox.ACL.Grant;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AclPushSerializer
/*     */ {
/*     */   public static final String SEMICOLON_ESCAPE_SEQ = "*ASCII59*";
/*     */   
/*     */   public static String serialize(ShareInfoData shareInfoData)
/*     */   {
/*  43 */     return serialize(shareInfoData.getItemId(), shareInfoData.getItemUuid(), shareInfoData.getPath(), shareInfoData.getFolderDefaultViewCode(), shareInfoData.getType(), shareInfoData.getGranteeId(), shareInfoData.getGranteeName(), shareInfoData.getGranteeTypeCode(), shareInfoData.getRightsCode(), shareInfoData.getExpiry());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String serialize(MailItem item, ACL.Grant grant)
/*     */   {
/*  57 */     return serialize(item.getId(), item.getUuid(), (item instanceof Folder) ? ((Folder)item).getPath() : item.getName(), (item instanceof Folder) ? ((Folder)item).getDefaultView() : item.getType(), item.getType(), grant.getGranteeId(), grant.getGranteeName(), grant.getGranteeType(), grant.getGrantedRights(), grant.getEffectiveExpiry(item.getACL()));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String serialize(int itemId, String itemUuid, String path, MailItem.Type folderDefaultView, MailItem.Type type, String granteeId, String granteeName, byte granteeType, short rights, long expiry)
/*     */   {
/*  72 */     if ((granteeName == null) && (granteeId != null)) {
/*     */       try {
/*  74 */         switch (granteeType) {
/*     */         case 1: 
/*  76 */           Account granteeAcct = Provisioning.getInstance().get(Key.AccountBy.id, granteeId);
/*  77 */           if (granteeAcct != null) {
/*  78 */             granteeName = granteeAcct.getName();
/*     */           }
/*     */           break;
/*     */         case 2: 
/*  82 */           DistributionList granteeDL = Provisioning.getInstance().get(Key.DistributionListBy.id, granteeId);
/*  83 */           if (granteeDL != null) {
/*  84 */             granteeName = granteeDL.getName();
/*     */           }
/*     */           break;
/*     */         case 4: 
/*  88 */           Domain granteeDomain = Provisioning.getInstance().get(Key.DomainBy.id, granteeId);
/*  89 */           if (granteeDomain != null) {
/*  90 */             granteeName = granteeDomain.getName();
/*     */           }
/*     */           break;
/*     */         case 5: 
/*  94 */           Cos granteeCos = Provisioning.getInstance().get(Key.CosBy.id, granteeId);
/*  95 */           if (granteeCos != null) {
/*  96 */             granteeName = granteeCos.getName();
/*     */           }
/*     */           break;
/*     */         }
/*     */       }
/*     */       catch (ServiceException e) {
/* 102 */         ZimbraLog.misc.info("Error in getting grantee name for grantee id %s", granteeId, e);
/*     */       }
/*     */     }
/* 105 */     if ((granteeType == 7) && (granteeId != null)) {
/* 106 */       granteeId = granteeId.toLowerCase();
/*     */     }
/*     */     
/* 109 */     if (path.contains(";")) {
/* 110 */       path = path.replaceAll(";", "*ASCII59*");
/*     */     }
/* 112 */     StringBuilder sb = new StringBuilder().append("granteeId:").append(granteeId).append(";granteeName:").append(granteeName).append(";granteeType:").append(ACL.typeToString(granteeType)).append(";folderId:").append(itemId).append(";folderUuid:").append(itemUuid).append(";folderPath:").append(path).append(";folderDefaultView:").append(folderDefaultView).append(";rights:").append(ACL.rightsToString(rights)).append(";type:").append(type);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 122 */     if (expiry != 0L) {
/* 123 */       sb.append(";expiry:").append(expiry);
/*     */     }
/* 125 */     return sb.toString();
/*     */   }
/*     */   
/*     */   public static ShareInfoData deserialize(String sharedItemInfo) throws ServiceException {
/* 129 */     String[] parts = sharedItemInfo.split(";");
/* 130 */     Map<String, String> attrs = new HashMap();
/* 131 */     String key = null;
/* 132 */     for (String part : parts) {
/* 133 */       String[] x = part.split(":", 2);
/* 134 */       if (x.length == 2) {
/* 135 */         attrs.put(x[0], x[1]);
/* 136 */         key = x[0];
/*     */       } else {
/* 138 */         String value = (String)attrs.get(key);
/* 139 */         attrs.put(key, value + ";" + x[0]);
/*     */       }
/*     */     }
/* 142 */     ShareInfoData obj = new ShareInfoData();
/*     */     
/* 144 */     String granteeId = (String)attrs.get("granteeId");
/* 145 */     obj.setGranteeId("null".equals(granteeId) ? null : granteeId);
/* 146 */     String granteeName = (String)attrs.get("granteeName");
/* 147 */     obj.setGranteeName("null".equals(granteeName) ? null : granteeName);
/* 148 */     obj.setGranteeType(ACL.stringToType((String)attrs.get("granteeType")));
/* 149 */     obj.setItemId(Integer.valueOf((String)attrs.get("folderId")).intValue());
/* 150 */     String uuid = (String)attrs.get("folderUuid");
/* 151 */     obj.setItemUuid("null".equals(uuid) ? null : uuid);
/* 152 */     if (((String)attrs.get("folderPath")).contains("*ASCII59*")) {
/* 153 */       String temp = ((String)attrs.get("folderPath")).replaceAll("\\*ASCII59\\*", ";");
/* 154 */       obj.setPath(temp);
/*     */     } else {
/* 156 */       obj.setPath((String)attrs.get("folderPath"));
/*     */     }
/*     */     
/* 159 */     obj.setFolderDefaultView(MailItem.Type.of((String)attrs.get("folderDefaultView")));
/* 160 */     obj.setRights(ACL.stringToRights((String)attrs.get("rights")));
/* 161 */     String type = (String)attrs.get("type");
/* 162 */     if (type != null) {
/* 163 */       obj.setType(MailItem.Type.of(type));
/*     */     } else {
/* 165 */       obj.setType(MailItem.Type.FOLDER);
/*     */     }
/* 167 */     String expiry = (String)attrs.get("expiry");
/* 168 */     if (expiry != null) {
/* 169 */       obj.setExpiry(Long.valueOf(expiry));
/*     */     }
/* 171 */     return obj;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/acl/AclPushSerializer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */